﻿using STHPMS1.BLL.B_Core;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore;
using STHPMS1.ICore.I_BLL.Bus;
using STHPMS1.ICore.I_DAL;
using STHPMS1.ICore.I_Entity.Info;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.ICore.I_Serv;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace STHPMS1.BLL.B_Bus
{
    public class Dn_Traffic_WayBus : BllBase, IDn_Traffic_WayBill
    {
        public void Save<T>(T entity)
            where T : class ,IDn_Traffic_Way
        {
            if (this.Scene.Dal.Sthpms1.Update(entity) == 0)
            {
                this.Scene.Dal.Sthpms1.Insert(entity);
            }
        }

        public void Remove(IDn_Traffic_Way entity)
        {
            this.Scene.Dal.Sthpms1.Delete(entity);
        }

        public IEnumerable<T> Get<T>(Expression<Func<T, bool>> predicate, IPagingInfo info)
            where T : class, IDn_Traffic_Way
        {
            return this.Scene.Dal.Sthpms1.Select<T>(predicate, info);
        }

        /// <summary>
        /// 返回路段编号对应的轴载设计当量
        /// </summary>
        /// <param name="segid"></param>
        /// <returns></returns>
        public double Exists(string segid) 
        {
            ISthpms1Dao dao = this.Scene.Dal.Sthpms1;
            List<double> h= dao.Column<double>(dao.From<IDn_Traffic_Way>().Select(x => x.Accuequ_Load)
                         .Where(q => q.Segid == segid));
            if(h.Count>0)
            {
                return h[0];
            }
            return 0;
        }

        public void Update(IDn_Traffic_Way entity)          
        {
            this.Scene.Dal.Sthpms1.Dn_Traffic_Way.Update(entity);
        }


        public List<string> GetYear(IB_Invntory b)
        {
            return this.Scene.Dal.Sthpms1.Dn_Traffic_Way.GetYear(b);
        }
    }
}
